# -*- coding: UTF-8 -*-
import webbrowser
import tkinter as tk
from Code.View.sc_global import Global
from Code.View.sc_base import TopWinBase
from Code.View.Datamation.sc_provide import view_gate


class AboutTop(TopWinBase):
    """ 关于信息栏 """
    def pack(self):
        def show_hand_cursor(event):
            text.config(cursor='arrow')

        def show_xterm_cursor(event):
            text.config(cursor='xterm')

        def click(event):
            webbrowser.open(url)

        self.master.title(view_gate.query_language_data('ABOUT_SOFTWARE'))
        self.resize(500, 380)
        # ico
        tk.Label(self.master, image=view_gate.query_photo_image_data('ABOUT')).pack()
        # 中间部分说明
        text = tk.Text(self.master, width=100, height=22)
        text.pack()
        # 底部版权说明
        tk.Label(self.master, text=view_gate.query_env_define_data('G_COPYRIGHT_INFO')).pack()

        infos = view_gate.query_about_info_data()
        website = infos.split('\n')[-1]
        index = website.index('http')
        url = website[index:]
        text.insert('end', '%s\n' % infos)
        count = text.get('1.0', 'end').count('\n') - 1
        text.tag_add('head', '1.0', '1.end')
        text.tag_config('head', font=(Global.G_TEXT_FONT, 12, 'bold'))
        text.tag_add('link', "%s.%s" % (count, index), "%s.end" % count)
        text.tag_config('link', foreground='blue', underline=True)
        text.tag_bind('link', '<Enter>', show_hand_cursor)
        text.tag_bind('link', '<Leave>', show_xterm_cursor)
        text.tag_bind('link', '<Button-1>', click)
        text['stat'] = 'disabled'

